package cn.jboa.action;

import cn.jboa.common.Constants;
import cn.jboa.entity.SysEmployee;
import cn.jboa.service.EmployeeService;

public class EmployeeAction extends BaseAction {

    private SysEmployee employee;
    private EmployeeService employeeService;
    private String msg;
    private SysEmployee manager;
    private String random;

    public String login(){
        Object sessionRandom  = this.getSession().get("random");
        if (random == null || !random.equals(sessionRandom)) {
            this.addActionError(this.getText("errors.codeerror"));
            msg = this.getText("errors.codeerror");
            return INPUT;
        }
        try {
            employee = employeeService.login(employee);
            manager=employeeService.getManager(employee);
            this.getSession().put(Constants.AUTH_EMPLOYEE,employee);
            this.getSession().put(Constants.AUTH_EMPLOYEE_MANAGER,manager);
            this.getSession().put(Constants.EMPLOYEE_POSITION,employee.getSysPosition().getNameCn());
        } catch (cn.jboa.exception.JboaException e) {
            this.addActionError(this
                    .getText("errors.invalid.usernameorpassword"));
            msg = this.getText("errors.invalid.usernameorpassword");

        }
        if (this.hasActionErrors())// if (msg != null)
            return INPUT;

        return  SUCCESS;
    }

    public SysEmployee getEmployee() {
        return employee;
    }

    public void setEmployee(SysEmployee employee) {
        this.employee = employee;
    }

    public EmployeeService getEmployeeService() {
        return employeeService;
    }

    public void setEmployeeService(EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public SysEmployee getManager() {
        return manager;
    }

    public void setManager(SysEmployee manager) {
        this.manager = manager;
    }

    public String getRandom() {
        return random;
    }

    public void setRandom(String random) {
        this.random = random;
    }
}

